package com.luanye.enjoy.controller;

import com.luanye.enjoy.dto.ConditionDTO;
import com.luanye.enjoy.dto.UserConfigDTO;
import com.luanye.enjoy.dto.UserDTO;
import com.luanye.enjoy.entity.User;
import com.luanye.enjoy.service.UserService;
import com.luanye.enjoy.vo.RespBean;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/wx")
@AllArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping("/validate")
    public RespBean wxLogin(String jscode){
        return userService.wxLogin(jscode);
    }

    @PostMapping("/register")
    public RespBean register(@RequestBody UserDTO user, HttpServletRequest request) {
        return userService.register(user, request);
    }

    @GetMapping("/updateLoc")
    public RespBean updateLocation(@RequestBody User user){
        return userService.updateLoc(user);
    }

    @PutMapping("/info")
    public RespBean updateUserConfig(@RequestBody UserConfigDTO dto){
        return userService.updateUserConfig(dto);
    }

    @PutMapping("/phone/{phone}/{code}")
    public RespBean updatePhone(@PathVariable("phone") String phone,
                                @PathVariable("code") String code
                                ){
        return userService.updatePhoneByCode(phone, code);
    }

    @PostMapping("/sms")
    public RespBean registerSms(@RequestBody ConditionDTO dto){
        return userService.registerSms(dto.getPhone());
    }

}
